package cn.edu.zjgsu.ito.config;

import cn.edu.zjgsu.ito.model.Classroom;
import cn.edu.zjgsu.ito.model.Course;
import cn.edu.zjgsu.ito.model.Major;
import cn.edu.zjgsu.ito.model.Newpassportno;
import cn.edu.zjgsu.ito.model.StudentGrade;
import cn.edu.zjgsu.ito.model.StudentInfo;
import cn.edu.zjgsu.ito.model.StudentTimetable;
import cn.edu.zjgsu.ito.model.TeacherInfo;
import cn.edu.zjgsu.ito.model.TestModel;
import cn.edu.zjgsu.ito.model.Visa;
import cn.edu.zjgsu.ito.routes.AdminRoutes;
import cn.edu.zjgsu.ito.routes.CommonRoutes;
import cn.edu.zjgsu.ito.routes.StudentRoutes;
import cn.edu.zjgsu.ito.routes.TeacherRoutes;
import cn.edu.zjgsu.ito.interceptor.GlobalInterceptor;
import cn.edu.zjgsu.ito.model.College;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;


public class MyConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		
		me.setBaseViewPath("/WEB-INF/htmls");

		me.setError404View("/WEB-INF/htmls/common/errors/404.html");

		me.setError500View("/WEB-INF/htmls/common/errors/500.html");
		
		me.setFileRenderPath("/WEB-INF/template");
	}

	@Override
	public void configRoute(Routes me) {
		me.add(new CommonRoutes());

		me.add(new AdminRoutes());

		me.add(new StudentRoutes());
		
		me.add(new TeacherRoutes());
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("db.properties");
		//System.out.println(getProperty("jdbcUrl"));
		C3p0Plugin cp = new C3p0Plugin(getProperty("jdbcUrl"),getProperty("user"),getProperty("password"),getProperty("driverClass"));
		me.add(cp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		arp.addMapping("major", Major.class);
		arp.addMapping("course", Course.class);
		arp.addMapping("classroom", Classroom.class);
		arp.addMapping("teacher_info", TeacherInfo.class);
		arp.addMapping("student_info", StudentInfo.class);
		arp.addMapping("student_grade", StudentGrade.class);
		arp.addMapping("student_timetable", StudentTimetable.class);
		arp.addMapping("college", College.class);
		arp.addMapping("visa", Visa.class);
		arp.addMapping("test", TestModel.class);
		arp.addMapping("newpassportno", Newpassportno.class);
		me.add(arp);
		
	}

	public void configInterceptor(Interceptors me)
	{
		//session
		me.add(new SessionInViewInterceptor());
		me.add(new GlobalInterceptor());
	}

	public void configHandler(Handlers me)
	{

		me.add(new ContextPathHandler("path"));
       /* me.add(new UploadHandler());*/
	}
}
